from django.shortcuts import redirect


class LoginMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        whiltlist = ['/user/login/','/user/register/','/admin/login/','/admin/','/index/']
        path = request.path
        if path in whiltlist or request.user.is_authenticated:
            response = self.get_response(request)
            return response
        else:
            return redirect('user:login')